﻿using System.Web.UI;
using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.RepositoryFramework;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.Adver;

namespace Ue.Qcdz.UI.Controls.Adver
{
    public class AdvertImgView : SkinnedControl
    {
        #region Overrides of SkinnedControl

        private string skinFileName = "~/Themes/zh-cn/Skins/AdvertImgView.ascx";
        public string WebSiteName { get; set; }
        public string PageName { get; set; }
        public string DivId { get; set; }
        private Image imgPic;
        private HyperLink hypLink;
        private IAdvertisementRepository repository;
        protected override string GetSkinFileName()
        {
            return skinFileName;
        }

        protected override void InitializeSkin(Control skin)
        {
            imgPic = skin.FindControl<Image>("imgPic");
            hypLink = skin.FindControl<HyperLink>("hypLink");
            GetAdInfo();
        }
        private void GetAdInfo()
        {
            this.repository = RepositoryFactory.GetRepository<IAdvertisementRepository, Domain.Adver.Advertisement>();
             Domain.Adver.Advertisement advertisement = repository.FindBy(WebSiteName, PageName, DivId);
            imgPic.ImageUrl = advertisement.AdUrl;
            hypLink.NavigateUrl = advertisement.AdLink;
        }
        #endregion
    }
}
